package com.ppt.frame;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.ppt.constants.AppConstants;
import com.ppt.gestor.GestorPanel;
import com.ppt.operario.OperarioPanel;
import com.ppt.panel.HeaderPanel;
import com.ppt.toolbar.ToolBar;
import com.ppt.util.VariablesCompartidas;

@Entity
public class MainFrame extends JFrame {

	private static final long serialVersionUID = 1L;
	
	@OneToOne(mappedBy = "base")
	private ToolBar toolBar;
	@ManyToOne
	private HeaderPanel headerPanel;
	@ManyToOne
	private GestorPanel panelGestor;
	@OneToOne(mappedBy = "frame")
	private OperarioPanel panelOperario;
	
	public MainFrame() {
		initializeToolbar();
		initializeBody();
		
		
		this.setTitle("PPT Software - Control de Producción");
		this.setMinimumSize(new Dimension(AppConstants.MINIMUM_SIZE_X, AppConstants.MINIMUM_SIZE_Y));
		this.setLocationRelativeTo(null);
		this.setExtendedState(MAXIMIZED_BOTH);
		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
	}
	
	private void initializeToolbar() {
		toolBar = new ToolBar(this);
		getContentPane().add(toolBar, BorderLayout.PAGE_START);
	}

	private void initializeBody() {
		setLayout(new BorderLayout(0, 0));
		
		headerPanel = new HeaderPanel();
		getContentPane().add(headerPanel, BorderLayout.NORTH);
		
		if (VariablesCompartidas.operario){
			panelOperario = new OperarioPanel(this);
			getContentPane().add(panelOperario, BorderLayout.CENTER);
		}
		else{
			panelGestor = new GestorPanel();
			getContentPane().add(panelGestor, BorderLayout.CENTER);
		}
	}

}
